package pro.softzhang.algo.lc100;

import pro.softzhang.algo.common.TreeNode;

import java.util.Stack;

public class LC173_BinarySearchTreeIterator {
    public static void main(String[] args) {

    }

    static class BSTIterator {

        private Stack<TreeNode> stack;

        private TreeNode current;

        public BSTIterator(TreeNode root) {
            stack = new Stack();
            current = root;
        }

        public int next() {
            while (current != null) {
                stack.push(current);
                current = current.left;
            }

            current = stack.pop();
            int value = current.val;
            current = current.right;
            return value;
        }

        public boolean hasNext() {
            return current != null || !stack.isEmpty();
        }
    }
}